package com.ruoyi.classes.service.impl;

import com.ruoyi.classes.domain.Description;
import com.ruoyi.classes.mapper.DescriptionMapper;
import com.ruoyi.classes.service.DescriptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @Classname DescriptionServiceImpl
 * @Description
 * @Date 2025/5/20 16:33
 * @Created by 时光偷走初心
 */
@Service
public class DescriptionServiceImpl implements DescriptionService {

    @Autowired
    private DescriptionMapper descriptionMapper;
    @Override
    public void insert(Description description) {
        descriptionMapper.insert(description);
    }

    @Override
    public void delete(Long id) {
        descriptionMapper.deleteById(id);
    }

    @Override
    public void update(Description description) {
        delete(description.getId());
        insert(description);
    }

    @Override
    public List<Description> selectAll() {
        return descriptionMapper.findAll();
    }

    @Override
    public Description getById(Long id) {
        Optional<Description> description = descriptionMapper.findById(id);
        return description.orElse(new Description());
    }
}